import React, { useContext } from 'react';
import {ColorContext,UPDATE_COLOR} from './color'

function Button(){
    // {color: "red"}
// 因为dispatch已经存过状态{color: "blue", dispatch: ƒ}
    const {dispatch} = useContext(ColorContext)
    console.log( useContext(ColorContext))

    return (
        <div>
            <button onClick={()=>{dispatch({type:UPDATE_COLOR,color:"red"})}}>红色</button>
            <button onClick={()=>{dispatch({type:UPDATE_COLOR,color:"yellow"})}}>黄色</button>
        </div>
    )
}

export default Button